#!/usr/bin/env Python
# coding=utf-8
from sqlalchemy import Column
from sqlalchemy.types import CHAR, String, DateTime, UnicodeText, BigInteger, Boolean, Integer, Text, Float
from sqlalchemy import func, or_, not_

import methods.database.dbORM as dbORM

def init_db():
    dbORM.BaseModel.metadata.create_all(dbORM.engine)

def drop_db():
    dbORM.BaseModel.metadata.drop_all(dbORM.engine)

def getRoomInfo(data):
    param=""
    for i in data:
        param=param+","+i+"='"+data[i]+"'"
    query=dbORM.session.query(Room).filter(param[1:]).scalar()
    return query

def createRoom(data):
    room = Room()
    for i in data:
        setattr(room,i,data[i])
    dbORM.session.add(room)
    dbORM.session.commit()


class Room(dbORM.BaseModel):
    __tablename__ = 'room'
    id = Column(Integer, primary_key=True)
    username = Column(CHAR(50))
    room_id = Column(Integer)
    create_time = Column(DateTime)
    begin_time = Column(DateTime)
    end_time = Column(DateTime)

    def __repr__(self):
        return "<Room(username='%s',  room_id='%s',  create_time='%s',  begin_time='%s',  end_time='%s')>" % (self.username, self.room_id, self.create_time, self.begin_time, self.end_time)
